﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Windows.Ink;

namespace DentistApplication
{
    /// <summary>
    /// Interaction logic for PatientFile.xaml
    /// </summary>
    public partial class PatientFile : Window
    {
        String[] months = { "styczeń", "luty", "marzec", "kwiecień", "maj", "czerwiec", "lipiec", "sierpień", "wrzesień", "październik", "listopad", "grudzień" };
       
        int patientId;
        public PatientFile(int patientId)
        {
            InitializeComponent();
            this.patientId = patientId;

            bt_newVisit.Content = "Nowa\r\nwizyta";
            bt_patientData.Content = "    Dane\r\npersonalne";
            bt_treatmenthistory.Content = "Historia\r\nleczenia";
            bt_notes.Content = "Uwagi";
            fillHeader(DatabaseHandler.getPatient(patientId));
        }

        private void bt_newVisit_Click(object sender, RoutedEventArgs e)
        {
           
            panel_PatientNotes.Visibility = System.Windows.Visibility.Hidden;
            panel_treatmentHistory.Visibility = System.Windows.Visibility.Hidden;
            PF_NewVisit newVisit = new PF_NewVisit(this.patientId);
            newVisit.Show();
        }

        private void bt_patientData_Click(object sender, RoutedEventArgs e)
        {
            panel_PatientNotes.Visibility = System.Windows.Visibility.Hidden;
            panel_treatmentHistory.Visibility = System.Windows.Visibility.Hidden;
            PF_PersonalData personalData = new PF_PersonalData(this.patientId);
            personalData.Show();
        }

        private void fillHeader(Patient p)
        {
            la_nameLastname.Content = p.firstname+ " " + p.lastname;
            la_patientId.Content = "Numer kartoteki: " + p.id;
            la_age.Content = "Wiek: " + (DateTime.Now.Year - p.birthdate.Value.Year);
        }

        private void bt_treatmenthistory_Click(object sender, RoutedEventArgs e)
        {
            panel_treatmentHistory.Visibility = System.Windows.Visibility.Visible;
            panel_PatientNotes.Visibility = System.Windows.Visibility.Hidden;
            List<Service> listOfServices = DatabaseHandler.getPatientsAllServices(patientId);

            list_treatmentHistory.Items.Clear();

            listOfServices.ForEach(s => list_treatmentHistory.Items.Add(s.id_visit + ") data: "+ s.Visit.date.Day + " "+ 
                months[s.Visit.date.Month -1]+", typ zabiegu: " +  s.Service_type.type_name + " Ząb:" + s.tooth));
        }

        private void bt_notes_Click(object sender, RoutedEventArgs e)
        {
            panel_PatientNotes.Visibility = System.Windows.Visibility.Visible;
            panel_treatmentHistory.Visibility = System.Windows.Visibility.Hidden;
            string notes = "";

            DatabaseHandler.getPatientsAllServices(patientId).ForEach(s => notes += s.notes);
            if (notes.Length == 0)
                box_PatientNotes.Text = "Brak notatek o pacjencie";
            else
                box_PatientNotes.Text = notes;
        }


    }
        
}
